﻿//Write a program to calculate n! for each n in the range [1..100].
//Hint: Implement first a method that multiplies a number represented as array of digits by given integer number. 


using System;
using System.Collections.Generic;

public class CalculateFactorial
{
    public static void Main()
    {
        Console.WindowWidth = 160;
        Console.WriteLine("List of factorials of numbers in rang[1...100]");
        List<List<int>> factorialList = new List<List<int>>();
        for (int i = 1; i <= 100; i++)
        {
            List<int> factorial = MultiplyIntegers(i);
            factorialList.Add(factorial);
            for (int j = factorial.Count - 1; j >= 0; j--)
            {
                Console.Write("{0}", factorial[j]);
            }
            Console.WriteLine();
        }
    }

    public static List<int> MultiplyIntegers(int number)
    {
        List<int> result = new List<int>();
        result.Add(1);
        int product = 0;
        int temp = 0;
        int reachIndex = 1;
        for (int i = 1; i <= number; i++)
        {
            int count = 0;
            int index = -1;
            do
            {
                product = ((result[count++] * i) + product / 10);
                temp = product;
                result[++index] = (byte)(temp % 10);
                temp /= 10;
                if (temp != 0 && result.Count < count + 1)
                {
                    result.Add(0);
                }
            } while (count < reachIndex || temp != 0);

            reachIndex = count;
        }
        return result;
    }
}